package xutil

import (
	"math/rand"
	"time"
)

func RndTime(max int64) time.Duration {
	if max == 0 {
		return 0
	}

	rand.Seed(time.Now().Local().UnixNano())
	return time.Duration(rand.Int63() % max)
}

func Parse(layout, value string) (time.Time, error) {
	return time.ParseInLocation(layout, value, time.Now().Local().Location())
}

func Unix() int64 {
	return time.Now().Local().Unix()
}

func UnixNano() int64 {
	return time.Now().Local().UnixNano()
}

func MicroTime() float64 {
	return float64(UnixNano()) / 1e9
}
